package com.hxzy.common.util;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;


@Getter
@Setter
public class R<T> implements Serializable {
    private Integer code;
    private String msg;
    private T data;


    public R() {
        this.code=200;
        this.msg="success";
    }

    public static R ok() {
        return new R();
    }

    public static R ok(String msg) {
        R r = new R();
        r.msg=msg;
        return r;
    }

    public static <T> R ok( T data) {
        R<T> r = new R();
        r.data=data;
        return r;
    }

    public static R error(int code, String msg) {
        R r = new R();
        r.code=code;
        r.msg=msg;
        return r;
    }

    public static R error(String msg) {
        return error(500, msg);
    }

    public static R error() {
        return error(500, "未知异常，请联系管理员");
    }

}